package cn.scau.cmi.yeweijie.ORM;

import cn.scau.cmi.yeweijie.ORM.DAO.StudentDAO;
import cn.scau.cmi.yeweijie.ORM.DAO.TeacherDAO;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class Start {
    private static SessionFactory factory;
    public static void main(String[] args) {
        try{
            factory = new Configuration().configure().buildSessionFactory();
        }catch (Throwable ex) {
            System.err.println("Failed to create sessionFactory object." + ex);
            throw new ExceptionInInitializerError(ex);
        }
        TeacherDAO ME = new TeacherDAO(factory);
        StudentDAO STU =new StudentDAO(factory);
        Integer empID1 = ME.addTeacher(001, "梁山好汉");
        Integer empID2 = ME.addTeacher(002, "朱凯");
        Integer empID3 = ME.addTeacher(003, "毛宜军");

        Integer stuID1 = STU.addStudent(0425,"安冬旭",001);
        Integer stuID2 = STU.addStudent(0426,"梁志豪",001);
        Integer stuID3 = STU.addStudent(0427,"黄祖茂",002);
        Integer stuID4 = STU.addStudent(0123,"黄子韬",002);
        Integer stuID5 = STU.addStudent(0124,"黎顺钊",003);
        Integer stuID6 = STU.addStudent(0125,"苑子豪",003);

        STU.listStudent();
        ME.listTeacher();

        ME.updateTeacher(003,"刘雅红");

        ME.listTeacher();

        STU.deleteStudent(83);
    }
}
